package com.example.demo.saToken.listener;

import cn.dev33.satoken.listener.SaTokenListener;
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import org.springframework.stereotype.Component;

/**
 * @ClassName MySaTokenListener
 * @Description 自定义侦听器
 * @Author MingChang.Wei
 * @Date 2024/9/23
 **/
@Component
public class MySaTokenListener implements SaTokenListener {
    
    private static final Log log = LogFactory.get();
    
    @Override
    public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginParameter loginParam) {
        log.info("用户登录成功，loginType: {}, loginId: {}, tokenValue: {}", loginType, loginId, tokenValue);
    }

    @Override
    public void doLogout(String loginType, Object loginId, String tokenValue) {
        log.info("用户退出登录，loginType: {}, loginId: {}, tokenValue: {}", loginType, loginId, tokenValue);
    }

    @Override
    public void doKickout(String loginType, Object loginId, String tokenValue) {
        log.warn("用户被踢下线，loginType: {}, loginId: {}, tokenValue: {}", loginType, loginId, tokenValue);
    }

    @Override
    public void doReplaced(String loginType, Object loginId, String tokenValue) {
        log.warn("用户被顶下线，loginType: {}, loginId: {}, tokenValue: {}", loginType, loginId, tokenValue);
    }

    @Override
    public void doDisable(String loginType, Object loginId, String service, int level, long disableTime) {
        log.warn("用户被封禁，loginType: {}, loginId: {}, service: {}, level: {}, disableTime: {}", 
                loginType, loginId, service, level, disableTime);
    }

    @Override
    public void doUntieDisable(String loginType, Object loginId, String service) {
        log.info("用户解除封禁，loginType: {}, loginId: {}, service: {}", loginType, loginId, service);
    }

    @Override
    public void doOpenSafe(String loginType, String tokenValue, String service, long safeTime) {
        log.info("开启二级认证，loginType: {}, tokenValue: {}, service: {}, safeTime: {}", 
                loginType, tokenValue, service, safeTime);
    }

    @Override
    public void doCloseSafe(String loginType, String tokenValue, String service) {
        log.info("关闭二级认证，loginType: {}, tokenValue: {}, service: {}", loginType, tokenValue, service);
    }

    @Override
    public void doCreateSession(String sessionId) {
        log.debug("创建会话，sessionId: {}", sessionId);
    }

    @Override
    public void doLogoutSession(String sessionId) {
        log.debug("会话注销，sessionId: {}", sessionId);
    }

    @Override
    public void doRenewTimeout(String loginType, Object loginId, String tokenValue, long timeout) {
        log.debug("续签Token，loginType: {}, loginId: {}, tokenValue: {}, timeout: {}秒", 
                loginType, loginId, tokenValue, timeout);
    }
}
